<?php

class ConversationReply extends \Phalcon\Mvc\Model
{

    /**
     *
     * @var integer
     */
    public $id;

    /**
     *
     * @var integer
     */
    public $c_id;

    /**
     *
     * @var integer
     */
    public $sender_id;

    /**
     *
     * @var string
     */
    public $message;

    /**
     *
     * @var string
     */
    public $date_created;

    /**
     *
     * @var string
     */
    public $ip;

    /**
     *
     * @var integer
     */
    public $has_cleared;

    /**
     *
     * @var integer
     */
    public $has_seen;

    /**
     * Independent Column Mapping.
     */
    public function columnMap()
    {
        return array(
            'id' => 'id', 
            'c_id' => 'c_id', 
            'sender_id' => 'sender_id', 
            'message' => 'message', 
            'date_created' => 'date_created', 
            'ip' => 'ip', 
            'has_cleared' => 'has_cleared', 
            'has_seen' => 'has_seen'
        );
    }

    public function beforeValidationOnCreate()
    {
        $this->date_created = CURR_DATE;
        $this->has_seen = 0;
        $this->has_cleared = 0;
        
    }

    public function listMessages($c_id)
    {
        $phql = "SELECT cr.*,uat.fname,uat.lname,uat.profile_pic FROM ConversationReply cr 
                 LEFT JOIN UserAccountTb uat ON uat.id = cr.sender_id
                 WHERE cr.c_id = ?0
                 ORDER BY cr.date_created ASC
                 ";
        $data = $this->modelsManager->executeQuery($phql,array(0=>$c_id));

        return $data;
    }

}
